<?php
/**
 * Created by PhpStorm.
 * User: chenzhitao
 * Date: 2018/6/21
 * Time: 下午2:54
 */

namespace app\index\service;


use app\index\model\Company;

class CompanyService
{
    /**
     * 获取首页公司推荐列表
     */
    const REC_COMPANY_LIST_KEY = "REC_COMPANY_LIST_KEY";
    const COMPANY_LIST_KEY = "COMPANY_LIST_KEY";
    const COMPANY_DETAIL = "COMPANY_DETAIL";
    const EXPIRE_IN = 60*60*12;
    public static function getIndexCompanyList(){
        $cache_company_list = cache(self::REC_COMPANY_LIST_KEY);
        if($cache_company_list){
            return $cache_company_list;
        }

        $data = Company::getRecList();
        cache(self::REC_COMPANY_LIST_KEY,$data,self::EXPIRE_IN);
        return $data;
    }
    public static function getCompanyList($page){
        $cache_company_list = cache(self::COMPANY_LIST_KEY.$page);
        if($cache_company_list){
            return $cache_company_list;
        }
        $data = Company::getList($page);
        cache(self::COMPANY_LIST_KEY.$page,$data,self::EXPIRE_IN);
        return $data;

    }
    public static function getCompanyDetail($id){
        $cache_company_detail = cache(self::COMPANY_DETAIL.$id);
        if($cache_company_detail){
            return $cache_company_detail;
        }
        $data = Company::getOne($id);
        cache(self::COMPANY_DETAIL.$id,$data,self::EXPIRE_IN);
        return $data;
    }

}